﻿package cn.poco.pepsi.util;

import android.location.Location;
import android.location.LocationListener;
import android.location.GpsStatus.Listener;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
/*
 */
public class GpsListener implements LocationListener,Listener{
	 Handler currHandler;
	public GpsListener(Handler handler){
		this.currHandler = handler;
	}
	@Override
	public void onLocationChanged(Location location) {
		// 当坐标改变时触发此函数，如果Provider传进相同的坐标，它就不会被触发
		if (location != null) {
			Message msg = new Message();
			msg.what = Cons.GPS_LOCATION_CHANGE;
			Bundle bundle  = new Bundle();
			Cons.GPS_LAT_DATA = String.valueOf(location.getLatitude()); 
			Cons.GPS_LON_DATA = String.valueOf(location.getLongitude());
			bundle.putDouble(Cons.GPS_LAT, location.getLatitude());
			bundle.putDouble(Cons.GPS_LONG, location.getLongitude());
			msg.setData(bundle);
			currHandler.sendMessage(msg);
		}
	}
	@Override
	public void onProviderDisabled(String provider) {
		/// Provider被disable时触发此函数，比如GPS被关闭 			
	}
	@Override
	public void onProviderEnabled(String provider) {
		// Provider被enable时触发此函数，比如GPS被打开 		
	}
	@Override
	public void onStatusChanged(String provider, int status,
			Bundle extras) {
		// Provider的转态在可用、暂时不可用和无服务三个状态直接切换时触发此函数 			
	}
	@Override
	public void onGpsStatusChanged(int event) {
		
		
	}

}
